package com.finance.cooperate.feature.service.impl;

import com.finance.cooperate.common.utils.StringUtil;
import com.finance.cooperate.dao.entity.primary.User;
import com.finance.cooperate.dao.repository.primary.UserRepository;
import com.finance.cooperate.feature.dto.UserDTO;
import com.finance.cooperate.feature.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author shen
 * @Date 2023/8/7 10:00
 * @Modify ...
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public UserDTO getInfo(String uid) {

        UserDTO dto = new UserDTO();

        Optional<User> optional = userRepository.findById(uid);

        if (optional.isPresent()) {

            User user = optional.get();

            Integer locationType = user.getLocationType();
            dto.setLocationType(locationType);

            String street = user.getStreet();
            if (StringUtil.isEmptyOrNvl(street)) {
                dto.setStreetIsNull(1);
            } else {
                dto.setStreetIsNull(0);
            }

            dto.setPackageName(user.getPackageName());

            dto.setIsBlacklist(user.getIsBlacklist());

            dto.setUserType(user.getUserType());

        }


        return dto;
    }

    @Override
    public String getDeviceId(String uid) {

        Optional<User> optional = userRepository.findById(uid);
        if (optional.isPresent()) {
            User user = optional.get();

            return user.getDeviceId();
        }


        return null;
    }
}
